package phoenix.core.helpers.extensions;

import org.testng.Assert;

import phoenix.core.PhoenixManager;
import phoenix.core.data_models.TestUserDataModel;
import phoenix.core.data_models.UserProfileDataModel.ProfileDetails;
import phoenix.web.test_objects.data_model.NaughtyMode;
import core.ApplicationManager;
import core.helpers.TestHelper;

/**
 * Class provides functions for values testing
 */
public class TestHelperExt extends TestHelper
{
	// PhoenixManager instance
	protected static PhoenixManager phoenix;

	/**
	 * Initializes TestHelperExt
	 * @param p_manager ApplicationManager instance
	 * @param p_phoenix PhoenixManager instance
	 */
	public TestHelperExt(ApplicationManager p_manager, PhoenixManager p_phoenix)
	{
		super(p_manager);
		phoenix = p_phoenix;
	}

	public void sessionRestore(TestUserDataModel p_user)
	{
		try
		{
			// Back to user session
			phoenix.setTestUser(p_user);
			phoenix.wd().wait(2);
			phoenix.wd().openURL(p_user.getAutologin());
			phoenix.wd().wait(2);
		}
		catch (Exception p_ex)
		{
			phoenix.log().errorAndScreen("sessionRestore " + p_ex.toString());
		}
	}

	/**
	 * Throws assertion error
	 * @param p_errors Error messages list
	 * @throws AssertionError
	 */
	@Override
	protected void throwError(String... p_errors)
	{
		if (phoenix.config().REDMINE_POST_ERRORS)
		{
			phoenix.redmine().postError();
		}

		super.throwError(p_errors);
	}

	public void assertEqualsWithScreenPersonalInfo(ProfileDetails p_actual, ProfileDetails p_expected, String p_page)
	{
		assertEqualsWithScreen(p_actual.height, p_expected.height, "Height display on " + p_page);
		assertEqualsWithScreen(p_actual.weight, p_expected.weight, "Weight display on " + p_page);
		assertEqualsWithScreen(p_actual.bodyType, p_expected.bodyType, "Body type display on " + p_page);
		assertEqualsWithScreen(p_actual.hairColor, p_expected.hairColor, "Hair color display on " + p_page);
		assertEqualsWithScreen(p_actual.eyesColor, p_expected.eyesColor, "Eyes color display on " + p_page);
		assertEqualsWithScreen(p_actual.pircing, p_expected.pircing, "Pircing display on " + p_page);
		assertEqualsWithScreen(p_actual.tattoo, p_expected.tattoo, "Tattoo display on " + p_page);
		assertEqualsWithScreen(p_actual.orientation, p_expected.orientation, "Orientation display on " + p_page);
		assertEqualsWithScreen(p_actual.maritalStatus, p_expected.maritalStatus, "Marital status display on " + p_page);
		assertEqualsWithScreen(p_actual.children, p_expected.children, "Children display on " + p_page);
		assertEqualsWithScreen(p_actual.living, p_expected.living, "Living display on " + p_page);
		assertEqualsWithScreen(p_actual.income, p_expected.income, "Income display on " + p_page);
		assertEqualsWithScreen(p_actual.smoke, p_expected.smoke, "Smoke display on " + p_page);
		assertEqualsWithScreen(p_actual.drink, p_expected.drink, "Drink display on " + p_page);
		assertEqualsWithScreen(p_actual.ethnicOrigin, p_expected.ethnicOrigin, "Ethnic origin display on " + p_page);
		assertEqualsWithScreen(p_actual.religion, p_expected.religion, "Religion display on " + p_page);
		assertEqualsWithScreen(p_actual.education, p_expected.education, "Education display on " + p_page);
	}

	public void assertEqualsWithScreen(String p_actual, String p_expected, String p_message)
	{
		try
		{
			Assert.assertEquals(p_actual, p_expected);
		}
		catch (AssertionError p_ex)
		{
			phoenix.log().errorAndScreen(p_message + " : Actual: [" + p_actual + "] is NOT equal Expected: [" + p_expected + "] ");
		}
	}

	public void assertEqualsWithScreen(int p_actual, int p_expected, String p_message)
	{
		try
		{
			Assert.assertEquals(p_actual, p_expected);
		}
		catch (AssertionError p_ex)
		{
			phoenix.log().errorAndScreen(p_message + " " + p_ex.toString());
		}
	}

	public void assertEqualsWithScreen(boolean p_actual, boolean p_expected, String p_message)
	{
		try
		{
			Assert.assertEquals(p_actual, p_expected);
		}
		catch (AssertionError p_ex)
		{
			phoenix.log().errorAndScreen(p_message + " " + p_ex.toString());
		}
	}

	public void assertNotEqualsWithScreen(String p_idOfPhotoActual, String p_idOfPhotoPrevios, String p_message)
	{
		try
		{
			Assert.assertNotEquals(p_idOfPhotoActual, p_idOfPhotoPrevios);
		}
		catch (AssertionError p_ex)
		{
			phoenix.log().errorAndScreen(p_message + " " + p_ex.toString());
		}
	}

	public void assertEquals(NaughtyMode p_actual, NaughtyMode p_expected, String p_errorMessage)
	{
		try
		{
			Assert.assertEquals(p_actual.toString(), p_expected.toString());
		}
		catch (AssertionError p_ex)
		{
			phoenix.log().errorAndScreen(p_errorMessage + " " + p_ex.toString());
		}
	}
}
